package cm.config;

import liquibase.integration.spring.SpringLiquibase;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/***
 * @description: liquibase配置
 * @param:
 * @return:
 * @author yxh
 * @date: 2022/9/7
 */

//@Configuration
//public class LiquibaseConfig {
//
//    @Resource
//    private DataSource dataSource;
//
//    public LiquibaseConfig() {
//    }
//
//    /**
//     * liquibase bean声明
//     */
//    @Bean
//    public SpringLiquibase liquibase() {
//        SpringLiquibase liquibase = new SpringLiquibase();
//        // Liquibase文件路径
//        liquibase.setChangeLog("classpath:liquibase/changelog-master.xml");
//        liquibase.setDataSource(dataSource);
//        liquibase.setShouldRun(true);
//        liquibase.setResourceLoader(new DefaultResourceLoader());
//        return liquibase;
//    }
//}
@Configuration
@EnableConfigurationProperties(LiquibaseProperties.class)
public class LiquibaseConfig {

    @Bean
    public SpringLiquibase liquibase(DataSource dataSource,LiquibaseProperties liquibaseProperties) {
        SpringLiquibase springLiquibase = new SpringLiquibase();
        springLiquibase.setDataSource(dataSource);
        springLiquibase.setChangeLog(liquibaseProperties.getChangeLog());
        springLiquibase.setShouldRun(liquibaseProperties.isEnabled());
        springLiquibase.setDropFirst(liquibaseProperties.isDropFirst());
        System.err.println(springLiquibase.getChangeLog());
        return springLiquibase;
    }
}
